package com.zhouyer.study.controller;

import com.zhouyer.study.entity.ToEmail;
import com.zhouyer.study.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 邮件服务控制类
 *
 * @author zhouyao
 * @version 1.0
 * @date 2021/12/6 8:39 下午
 */
@RestController
@RequestMapping("/email")
public class EmailController {
    @Autowired
    private EmailService emailService;

    @GetMapping("/{email}/{code}")
    public boolean sendEmail(@PathVariable("email") String email, @PathVariable("code") String code) {
        System.out.println("================调用邮件服务，正在给" + email + "发送邮件");
        String emailSubject = "登录认证验证码";
        return emailService.sendSimpleEmail(ToEmail.builder().toUser(email).subject(emailSubject).content(code).build());
    }


}
